package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.annotation.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	@GetMapping("/userNickNameById/{id}")
	public Result<String> userNickNameById(@PathVariable("id") Long id){
		UserInfo userInfo = userInfoService.getById(id);
		String nickname = userInfo.getNickname();
		return Result.ok(nickname);
	}

	@GetMapping("/getUserInfo/{userId}")
	public Result<UserInfoVo> getUserInfo(@PathVariable("userId") Long userId){
		UserInfoVo userInfoVo = new UserInfoVo();
		UserInfo userInfo = userInfoService.getById(userId);
		BeanUtils.copyProperties(userInfo, userInfoVo);
		return Result.ok(userInfoVo);
	}

	@GuiGuLogin
	@PostMapping("userIsPaidTrack/{albumId}")
	public Result<Map<Long,Integer>> userIsPaidTrack(@PathVariable("albumId") Long albumId,@RequestBody List<Long> stackIds){
		Map<Long,Integer> map = userInfoService.userIsPaidTrack(albumId,stackIds);
		return Result.ok(map);
	}
}

